#include "CGprsEmulator.h"


CGprsEmulator* CGprsEmulator::NewL(RSocketServ &aSocketServ)
{
	CGprsEmulator * self = new (ELeave) CGprsEmulator (aSocketServ);
	CleanupStack::PushL( self );
	self->ConstructL();
	CleanupStack::Pop();
	return self;		
}

void CGprsEmulator::ConstructL()
{
	User::LeaveIfError(iSocketServ.Connect());
	iState = EGprsIdle;
}

CGprsEmulator::CGprsEmulator(RSocketServ &aSocketServ):iSocketServ(aSocketServ)
{
	
}

TInt CGprsEmulator::OpenConnection()
{
	if (iState == EGprsIdle)
	{
		iState = EGprsConnected;
	}
	return KErrNone;
}

void CGprsEmulator::CloseConnection()
{
	if (iState != EGprsIdle)
		iState = EGprsIdle;
}

CGprsEmulator::~CGprsEmulator()
{
		
	this->CloseConnection();
	iSocketServ.Close();

}

void CGprsEmulator::DataTransferredRequest(TUint& iUploadCounter, TUint& iDownloadCounter)
{
	TUint connectionuplinkVolume(0);
	TUint connectiondownlinkVolume(0);
	
	iUploadCounter = connectionuplinkVolume;
	iDownloadCounter = connectiondownlinkVolume;
	

}

void CGprsEmulator::DataTransferredRequest(TDes8& iUploadCounter, TDes8& iDownloadCounter)
{
	TUint connectionuplinkVolume(0);
	TUint connectiondownlinkVolume(0);
	TBuf<32> iUp;
	TBuf<32> iDown;
	
	DataTransferredRequest(connectionuplinkVolume,connectiondownlinkVolume);
	
	iUp.Num(connectionuplinkVolume);
	iDown.Num(connectiondownlinkVolume);
	
	iUploadCounter.Zero();
	iDownloadCounter.Zero();
	iUploadCounter.Copy(_L("0"));
	iDownloadCounter.Copy(_L("0"));
	
	if (iUp.Length() <= iUploadCounter.MaxLength())
	{
		iUploadCounter.Copy(iUp);
	}
	
	if (iDown.Length() <= iDownloadCounter.MaxLength())
	{
		iDownloadCounter.Copy(iDown);
	}
}